//================================================================================================================================
//
//  Copyright (c) 2015-2018 VisionStar Information Technology (Shanghai) Co., Ltd. All Rights Reserved.
//  EasyAR is the registered trademark or trademark of VisionStar Information Technology (Shanghai) Co., Ltd in China
//  and other countries for the augmented reality technology developed by VisionStar Information Technology (Shanghai) Co., Ltd.
//
//================================================================================================================================

package com.easyarlibrary.artools.ar;

import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;

import com.easyarlibrary.app.BaseAppConstant;
import com.easyarlibrary.util.LoadTargetUtil;
import com.easyarlibrary.util.LogUtil;

import java.io.File;

import cn.easyar.ImageTracker;
import cn.easyar.TargetInstance;

/**
 * createTime：2019/2/25/025 on 17:04
 *
 * @author: jyc dell
 */
public class VideoAR extends BaseAR {

    private Handler handler;
    private String currVideo;
    private String currName;


    public VideoAR(Handler handler) {
        this.handler = handler;
    }


    public void setCurrVideo(String currVideo) {
        this.currVideo = currVideo;
    }

    public void setCurrName(String currName) {
        this.currName = currName;
    }

    @Override
    protected void initData(ImageTracker tracker) {
        LoadTargetUtil.loadAllFromAssetsJsonFile(tracker, BaseAppConstant.path + File.separator + currName + "/targets.json");
    }

    public void resetCurrPath() {
        currVideo = "";
    }

    @Override
    protected void doResule(TargetInstance targetInstance) {
        String currTempName = targetInstance.target().meta();
        if (!TextUtils.isEmpty(currVideo) && currVideo.equals(currTempName)) {
            return;
        }
        LogUtil.d("----识别结果----->" + targetInstance.target().meta());
        currVideo = currTempName;
        Message msg = new Message();
        msg.what = BaseAppConstant.HanlderWhat.HANDLE_WHAT_PLAY;
        msg.obj = currVideo;
        handler.sendMessage(msg);
    }
}